/**
 * Copyright (c) 2020-2021 浦东大爷 All rights reserved.
 * 机会永远都是留给有准备的人
 */
package com.job.moudle3.task5;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * @author: gitwo
 * @date: 2020-11-22
 * @description:斗地主类，实现发牌和打印
 */
public class Landlords {
    private List<Pok> player01 = new ArrayList<>();
    private List<Pok> player02 = new ArrayList<>();
    private List<Pok> player03 = new ArrayList<>();
    private List<Pok> holdPoker = new ArrayList<>();
    private Poker poker;

    public Landlords() {
        poker = new Poker(); // 生成一副牌
    }

    /**
     * 发牌方法，同时完成排序
     */
    public void deal() {
        for(int i = 0; i < poker.getPoker().size(); i++) {
            Pok pok = poker.getPoker().get(i);
            if(i > 50) holdPoker.add(pok);
            else if(i % 3 == 0)player01.add(pok);
            else if(i % 3 == 1)player02.add(pok);
            else if(i % 3 == 2)player03.add(pok);
        }
        // 自定义排序接口的实现
        Comparator<Pok> pokComparator = new Comparator<>() {

            @Override
            public int compare(Pok o1, Pok o2) {
                return o1.getId() - o2.getId();
            }
        };
        //手牌排序
        Collections.sort(player01, pokComparator);
        Collections.sort(player02, pokComparator);
        Collections.sort(player03, pokComparator);
//        Collections.sort(holdPoker, pokComparator);
    }

    /**
     * 洗牌，同时清除玩家手上的牌
     */
    public void shuffle() {
        poker.shuffle();
        player01.clear();
        player02.clear();
        player03.clear();
        holdPoker.clear();
    }
    public void show() {
        System.out.println("玩家1的牌是："+ player01.toString());
        System.out.println("玩家2的牌是："+ player02.toString());
        System.out.println("玩家3的牌是："+ player03.toString());

        System.out.println("底牌：" + holdPoker.toString());
    }

}
